package war2100.entity.npcs;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;

import org.newdawn.slick.geom.Vector2f;
import war2100.Prototypes;
import war2100.entity.Entity;
import war2100.entity.Map;
import war2100.game.helper.Vector2Helper;
import war2100.game.items.Pistol;
import war2100.game.items.Weapon;
import war2100.game.states.GameplayState;

public abstract class Npc extends Entity {

	protected Image img;
	protected Map map;
	protected GameplayState gameState;
	private float angle;
	
	private Weapon currentWeapon;

	public Npc(float x, float y, Image img, GameplayState gs, Prototypes prototypes) {
		super(x, y, prototypes);
		this.img = img;
		this.map = gs.getMap();
		this.gameState = gs;
		currentWeapon = new Pistol(gs);
		currentWeapon.setOwner(this);
	}

	public void render(Graphics g, GameContainer gc) {
		
		Vector2f position = getPosition(gc);
		Vector2f fieldSize = Vector2Helper.getFieldSize();
		
		if (getImage() != null) {
			getImage().setCenterOfRotation(fieldSize.getX()/2,  fieldSize.getY()/2);
			getImage().rotate(getAngle());
			getImage().draw(position.getX(), position.getY(), fieldSize.getX(), fieldSize.getY());
			getImage().rotate(-getAngle());
		}
	}
	
	

	
	
	
	
	public Vector2f getPosition(GameContainer gc)
	{
		Vector2f fieldSize = Vector2Helper.getFieldSize();
		Vector2f offset = Vector2Helper.getOffset(map, gc);
		
		float xPos = offset.getX() + (fieldSize.getX() * x);
		float yPos = offset.getY() +(fieldSize.getY() * y);
		
		return new Vector2f(xPos, yPos);
	}
	
	/**
	 * @return the img
	 */
	public Image getImage() {
		return img;
	}

	/**
	 * @param img the img to set
	 */
	public void setImage(Image img) {
		this.img = img;
	}

	/**
	 * @return the angle
	 */
	public float getAngle() {
		return angle;
	}

	/**
	 * @param angle the angle to set
	 */
	public void setAngle(float angle) {
		this.angle = angle;
	}

	/**
	 * @return the currentWeapon
	 */
	public Weapon getCurrentWeapon() {
		return currentWeapon;
	}

	/**
	 * @param currentWeapon the currentWeapon to set
	 */
	public void setCurrentWeapon(Weapon currentWeapon) {
		this.currentWeapon = currentWeapon;
	}

}
